"""
author: liuxu
date: 2024.12.3
description: Roctracer是一个用于跟踪运行时调用和异步活动的API库
"""
import allure
import pytest
from common.logger_ctrl import mylogger
from common.ssh_command import exec_cmd
from base_public.testbase import BasePublic


@allure.feature('roctracer测试')
@pytest.mark.high
class TestRoctracer(BasePublic):
    """测试roctracer功能"""
    def test_roctracer(self, test_env):
        """
        测试roctracer用例，查看打印日志是否齐全
        :return:
        """
        # 直接执行roctracer测例
        exe_path = self.compile_source_code(src_file_name='roctracer_case/roctracer_test.cpp',
                                            compile_paras=f"-I {self.rocm_path}/roctracer/include -O0 -g")
        ret, output = exec_cmd(f"{exe_path}", cwd=test_env)
        assert ret is True
        assert "test roctracer" in output and "pool_activity_callback" in output

    def test_roctracer_hipprof_trace_off(self, test_env):
        """
        在hipprof打开--trace-off情况下，测试roctracer用例
        :return:
        """
        exe_path = self.compile_source_code(src_file_name='roctracer_case/roctracer_test.cpp',
                                            compile_paras=f"-I {self.rocm_path}/roctracer/include -O0 -g")
        # 使用hipprof执行roctracer测例
        ret, output = exec_cmd(f"hipprof --trace-off {exe_path}", cwd=test_env)
        assert ret is True
        assert self.check_trace_output_success(output) is True
        assert "test roctracer" in output and "pool_activity_callback" in output
